package com.ctshk.rpc.tour.service.impl;

import java.util.List;

import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ctshk.common.model.TokenUser;
import com.ctshk.common.service.support.BaseService;
import com.ctshk.common.utils.EntityUtil;
import com.ctshk.rpc.tour.dto.schedule.SeriesTripScheduleSubsidyDTO;
import com.ctshk.rpc.tour.entity.SeriesTripScheduleSubsidy;
import com.ctshk.rpc.tour.mapper.SeriesTripScheduleSubsidyMapper;
import com.ctshk.rpc.tour.req.schedule.SeriesTripScheduleSubsidyReq;
import com.ctshk.rpc.tour.service.ISeriesTripScheduleSubsidyService;

@DubboService
public class SeriesTripScheduleSubsidyServiceImpl extends ServiceImpl<SeriesTripScheduleSubsidyMapper, SeriesTripScheduleSubsidy> implements ISeriesTripScheduleSubsidyService, BaseService {

    /**
     * 团期--其他收入
     *
     * @param addTripScheduleReq
     * @param id
     */
    @Autowired
    private SeriesTripScheduleSubsidyMapper seriesTripScheduleSubsidyMapper;

    /**
     * 添加补贴
     *
     * @param seriesTripScheduleSubsidyReq
     */
    @Override
    public void addSubsidy(SeriesTripScheduleSubsidyReq seriesTripScheduleSubsidyReq, TokenUser tokenUser) {

        //1.转化数据
        SeriesTripScheduleSubsidy seriesTripScheduleSubsidy = newCreateEntity(SeriesTripScheduleSubsidy.class, seriesTripScheduleSubsidyReq, tokenUser);
        seriesTripScheduleSubsidyMapper.insert(seriesTripScheduleSubsidy);

    }

    /**
     * 查询补贴
     *
     * @param id  团期id
     * @return 补贴列表
     */
    @Override
    public List<SeriesTripScheduleSubsidyDTO> querySubsidies(Long id) {
        List<SeriesTripScheduleSubsidy> seriesTripScheduleSubsidyList = seriesTripScheduleSubsidyMapper.selectList(new QueryWrapper<SeriesTripScheduleSubsidy>().lambda().eq(SeriesTripScheduleSubsidy::getScheduleId, id));
        return EntityUtil.copyList(seriesTripScheduleSubsidyList, SeriesTripScheduleSubsidyDTO.class);
    }

    /**
     * 修改补贴
     *
     * @param seriesTripScheduleSubsidyReq
     * @param
     */
    @Override
    public void updateSubsidies(SeriesTripScheduleSubsidyReq seriesTripScheduleSubsidyReq, TokenUser tokenUser) {
        SeriesTripScheduleSubsidy seriesTripScheduleSubsidy = newUpdateEntity(SeriesTripScheduleSubsidy.class, seriesTripScheduleSubsidyReq, tokenUser);
        seriesTripScheduleSubsidyMapper.updateById(seriesTripScheduleSubsidy);
    }

    /**
     * 删除补贴
     */
    @Override
    public void deleteSubsidies(Long id) {
        if (id != null) {
            seriesTripScheduleSubsidyMapper.deleteById(id);
        }

    }


}
